Namespace Data

  ''' <summary>
  ''' Common data helper methods.
  ''' </summary>
  ''' <remarks></remarks>
  Public NotInheritable Class DataHelper

    ''' <summary>
    ''' Converts a date to a SQL Server int value.
    ''' </summary>
    ''' <param name="value">Date to convert.</param>
    ''' <returns>Date as <see cref="int32">integer</see>.</returns>
    ''' <remarks></remarks>
    Public Shared Function ConvertDateToSqlInt32(ByVal value As Date) As Int32

      Return Int32.Parse(value.Year.ToString(CultureInfo.InvariantCulture) + value.Month.ToString("00", CultureInfo.InvariantCulture) + value.Day.ToString("00"), CultureInfo.InvariantCulture)

    End Function

    ''' <summary>
    ''' Converts time to a SQL Server in value.
    ''' </summary>
    ''' <param name="value">Time to convert.</param>
    ''' <returns>Time as <see cref="Int32">integer</see>.</returns>
    ''' <remarks></remarks>
    Public Shared Function ConvertTimeToSqlInt32(ByVal value As Date) As Int32

      Return Int32.Parse(value.Hour.ToString(CultureInfo.InvariantCulture) + value.Minute.ToString("00", CultureInfo.InvariantCulture) + value.Second.ToString("00"), CultureInfo.InvariantCulture)

    End Function

    ''' <summary>
    ''' Converts a SQL Server int date and time to a DateTime value.
    ''' </summary>
    ''' <param name="sqlDate">SQL Server date.</param>
    ''' <param name="sqlTime">SQL Server time.</param>
    ''' <returns><see cref="DateTime">Date and Time</see>.</returns>
    ''' <remarks></remarks>
    Public Shared Function ConvertSqlDateTime(ByVal sqlDate As Int32, ByVal sqlTime As Int32) As DateTime
      Dim tempDate As String = sqlDate.ToString(CultureInfo.InvariantCulture)
      Dim tempTime As String = sqlTime.ToString("000000", CultureInfo.InvariantCulture)

      Return New Date(Int32.Parse(tempDate.Substring(0, 4), CultureInfo.InvariantCulture), Int32.Parse(tempDate.Substring(4, 2), CultureInfo.InvariantCulture), Int32.Parse(tempDate.Substring(6, 2), CultureInfo.InvariantCulture), Int32.Parse(tempTime.Substring(0, 2), CultureInfo.InvariantCulture), Int32.Parse(tempTime.Substring(2, 2), CultureInfo.InvariantCulture), Int32.Parse(tempTime.Substring(4, 2), CultureInfo.InvariantCulture))

    End Function


    Private Sub New()
    End Sub
  End Class
End Namespace
